package com.littcore.saas.rest.assistant;

import java.util.Date;

import javax.annotation.Resource;

import org.jsondoc.core.annotation.Api;
import org.jsondoc.core.annotation.ApiMethod;
import org.jsondoc.core.annotation.ApiQueryParam;
import org.jsondoc.core.annotation.ApiResponseObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.littcore.saap.assistant.dao.UserFavouriteDao;
import com.littcore.saap.assistant.po.UserFavourite;
import com.littcore.saap.assistant.service.IUserFavouriteService;
import com.littcore.saap.core.web.util.LoginUtils;

@Api(name = "收藏接口", description = "收藏任务，网盘等")
@Controller
public class UserFavouriteServiceController {
    
    @Resource
    private IUserFavouriteService userFavouriteService;
    
    @Resource
    private UserFavouriteDao favouriteDao;
    
    @ApiMethod(description = "收藏")
    @ApiResponseObject
    @ResponseBody
    @RequestMapping
    public UserFavourite save(@ApiQueryParam(name = "moduleCode",allowedvalues="task,shareFile") @RequestParam(required=true) String moduleCode,@ApiQueryParam(name = "recordId") @RequestParam(required=true) Integer recordId)
    { 
       UserFavourite favourite=new UserFavourite();
      favourite.setCreateBy(LoginUtils.getLoginOpId().intValue());
      favourite.setCreateDatetime(new Date());
      favourite.setModuleCode(moduleCode);
      favourite.setRecordId(recordId);
      favourite.setTenantId(LoginUtils.getTenantId());
      favourite.setParams("");
      
      Integer id=0;
      if(favouriteDao.findUnique(favourite.getModuleCode(), favourite.getRecordId(), favourite.getCreateBy(), favourite.getTenantId())==null){
         id= favouriteDao.save(favourite);
      }
      
       if(id==0){ 
      return null; 
       }else{
           return favouriteDao.load(id);
       }
    
    } 

}
